package com.huike.web.controller.report;



import com.huike.clues.domain.dto.ClueQueryDTO;
import com.huike.clues.domain.vo.ClueReportVo;
import com.huike.clues.domain.vo.SubjectVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.service.ITbClueService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.StringUtils;
import com.huike.contract.domain.dto.TbContractDTO;
import com.huike.contract.domain.vo.TbContractVO;
import com.huike.contract.service.ITbContractService;
import com.huike.report.domain.vo.LineChartVO;
import com.huike.report.domain.vo.VulnerabilityMapVo;
import com.huike.report.service.IReportService;

import com.huike.clues.domain.TbActivity;

import com.huike.report.domain.vo.ActivityStatisticsVo;

//import jdk.nashorn.internal.runtime.ListAdapter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;


import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController extends BaseController {

    @Autowired
    private IReportService iReportService;

    @Autowired
    private ITbContractService iTbContractService;
    // 假如
    @Autowired
    private TbClueMapper tbClueMapper;
    @Autowired
    private ITbClueService iTbClueService;

    // 获取线索列表
    @GetMapping("/cluesStatisticsList")
    public TableDataInfo getcluesStatisticsList(ClueQueryDTO clueReportVo, HttpServletRequest req) {
        if((!StringUtils.isEmpty(req.getParameter("params[beginCreateTime]")))&&
                (!StringUtils.isEmpty(req.getParameter("params[endCreateTime]")))) {
            clueReportVo.setBeginCreateTime(req.getParameter("params[beginCreateTime]"));
            clueReportVo.setEndCreateTime(req.getParameter("params[endCreateTime]"));
            clueReportVo.setOwner(req.getParameter("params[owner]"));
            clueReportVo.setId(Long.valueOf(req.getParameter("params[id]")));
        }

        List<ClueReportVo> clueReportVoList=iTbClueService.getcluesStatisticsList(clueReportVo);
        return  getDataTablePage(clueReportVoList);
    }




    /**
     * 线索统计每天时间列表
     */
    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO getCluesStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate beginCreateTime
            ,@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime){
        LineChartVO lineChartVO=iReportService.getCluesStatistics(beginCreateTime,endCreateTime);
        return lineChartVO;
    }

    /**
     * 客户统计时间列表
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endTime}")
    public LineChartVO getontractStatistics(@PathVariable String beginCreateTime
            ,@PathVariable String endTime){
        LineChartVO lineChartVO=iReportService.getontractStatistics(beginCreateTime,endTime);
        return lineChartVO;
    }

    /**
     * 学科分布
     */
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endTime}")
    public List<SubjectVo> getSubjectStatistics(@PathVariable String beginCreateTime
            ,@PathVariable String endTime){
        List<SubjectVo> subjectVoList=iReportService.getSubjectStatistics(beginCreateTime,endTime);
        return subjectVoList;
    }

    // 客户成交列表
    @GetMapping("/contractStatisticsList")
    public TableDataInfo contractStatisticsList(TbContractDTO clueReportVo, HttpServletRequest req) {
        if ((!StringUtils.isEmpty(req.getParameter("params[beginCreateTime]"))) &&
                (!StringUtils.isEmpty(req.getParameter("params[endCreateTime]")))) {
            clueReportVo.setBeginCreateTime(req.getParameter("params[beginCreateTime]"));
            clueReportVo.setEndCreateTime(req.getParameter("params[endCreateTime]"));
            clueReportVo.setChannel(req.getParameter("params[channel]"));
            clueReportVo.setCreateBy(req.getParameter("params[createBy]"));
            clueReportVo.setDeptId(Long.valueOf(req.getParameter("params[deptId]")));
        }

        List<TbContractVO> clueReportVoList = iTbContractService.contractStatisticsList(clueReportVo);
        return getDataTablePage(clueReportVoList);
    }

    /**
     * 渠道统计饼图
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public List<Map<String,Object>> chanelStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate beginCreateTime , @DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate endCreateTime){
        return iReportService.chanelStatistics(beginCreateTime,endCreateTime);
    }

    /**
     * 活动统计饼图
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public List<Map<String,Object>> activityStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate beginCreateTime , @DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate endCreateTime){
        return iReportService.activityStatistics(beginCreateTime,endCreateTime);
    }

    /**
     * 渠道统计报表
     * @param tbActivity
     * @return
     */
    @GetMapping("/activityStatisticsList")
    public TableDataInfo activityStatisticsList(TbActivity tbActivity){
          startPage();
        List<ActivityStatisticsVo> list = iReportService.activityStatisticsList(tbActivity);
        return getDataTable(list);
    }

    /**销售统计时间列表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO salesStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate beginCreateTime , @DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate endCreateTime) {
         LineChartVO lineChartVO = iReportService.salesStatistics(beginCreateTime,endCreateTime);
         return lineChartVO;
    }
    /**
     * 部门统计报表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo deptStatisticsList(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate beginCreateTime , @DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate endCreateTime){
        startPage();
       List<Map<String,Object>> list = iReportService.deptStatisticsList(beginCreateTime,endCreateTime);
        return getDataTable(list);
    }

    /**
     * 销售统计报表归属人
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/ownerShipStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo ownerShipStatisticsList(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate beginCreateTime , @DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate endCreateTime){
        startPage();
        List<Map<String,Object>> list = iReportService.ownerShipStatisticsList(beginCreateTime,endCreateTime);
        return getDataTable(list);
    }

    /**
     * 销售统计报表--归属渠道
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/channelStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo channelStatisticsList(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate beginCreateTime , @DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable LocalDate endCreateTime){
        startPage();
        List<Map<String,Object>> list = iReportService.channelStatisticsList(beginCreateTime,endCreateTime);
        return getDataTable(list);

    }



    /**
     * 漏斗图数据
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult getVulnerabilityMap(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                          @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        VulnerabilityMapVo vulnerabilityMapVo = iReportService.getVulnerabilityMap(beginCreateTime, endCreateTime);
        return AjaxResult.success(vulnerabilityMapVo);

    }
}
